package org.mybatis.generator.plugins.comment;

import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.XmlElement;

import java.util.Properties;

public class SwaggerApiCommentGenerator implements CommentGenerator {

    @Override
    public void addConfigurationProperties(Properties properties) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addFieldComment(Field field,
                                IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        // TODO Auto-generated method stub
        if (introspectedColumn.getRemarks() != null && !introspectedColumn.getRemarks().equals("")) {
//            field.addJavaDocLine("/**");
//            field.addJavaDocLine(" * " + introspectedColumn.getRemarks());
//            // addJavadocTag(field, false);
//            field.addJavaDocLine(" */");
            //生成api字段注解
            field.addJavaDocLine(String.format(" @ApiModelProperty(\"%s\")", introspectedColumn.getRemarks()));
        }
        if (field.getType().getShortName().equals("Date")) {
            field.addJavaDocLine("@JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
        }
    }

    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
        // TODO Auto-generated method stub
    }

    @Override
    public void addClassComment(InnerClass innerClass,
                                IntrospectedTable introspectedTable) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addClassComment(InnerClass innerClass,
                                IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addEnumComment(InnerEnum innerEnum,
                               IntrospectedTable introspectedTable) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addGetterComment(Method method,
                                 IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addSetterComment(Method method,
                                 IntrospectedTable introspectedTable,
                                 IntrospectedColumn introspectedColumn) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addGeneralMethodComment(Method method,
                                        IntrospectedTable introspectedTable) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addJavaFileComment(CompilationUnit compilationUnit) {
        // TODO Auto-generated method stub
        //entity 导入包
        if (compilationUnit instanceof TopLevelClass) {
            if (compilationUnit.getType().getPackageName().contains("entity")) {
                compilationUnit.addImportedType(new FullyQualifiedJavaType("io.swagger.annotations.ApiModelProperty"));
                compilationUnit.addImportedType(new FullyQualifiedJavaType("io.swagger.annotations.ApiModel"));
                compilationUnit.addImportedType(new FullyQualifiedJavaType("com.fasterxml.jackson.annotation.JsonFormat;"));
                ((TopLevelClass) compilationUnit).addAnnotation(String.format("@ApiModel(\"%s\")", compilationUnit.getType().getShortName()));
            }
        }
    }

    @Override
    public void addComment(XmlElement xmlElement) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addRootComment(XmlElement rootElement) {
        // TODO Auto-generated method stub

    }

}
